home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / libiberty / getcwd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-22  |  1.5 KB  |  66 lines

  1. /* Emulate getcwd using getwd.
  2.    Copyright 1991 Free Software Foundation, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /*
  19.  
  20. NAME
  21.  
  22.     getcwd -- get absolute pathname for current working directory
  23.  
  24. SYNOPSIS
  25.  
  26.     char *getcwd (char pathname[len], len)
  27.  
  28. DESCRIPTION
  29.  
  30.     Copy the absolute pathname for the current working directory into
  31.     the supplied buffer and return a pointer to the buffer.  If the 
  32.     current directory's path doesn't fit in LEN characters, the result
  33.     is NULL and errno is set.
  34.  
  35. BUGS
  36.  
  37.     Emulated via the getwd() call, which is reasonable for most
  38.     systems that do not have getcwd().
  39.  
  40. */
  41.  
  42. #include <sys/param.h>
  43. #include <errno.h>
  44.  
  45. extern char *getwd ();
  46. extern int errno;
  47.  
  48. char *
  49. getcwd (buf, len)
  50.   char *buf;
  51.   int len;
  52. {
  53.   char ourbuf[MAXPATHLEN];
  54.   char *result;
  55.  
  56.   result = getwd (ourbuf);
  57.   if (result) {
  58.     if (strlen (ourbuf) >= len) {
  59.       errno = ERANGE;
  60.       return 0;
  61.     }
  62.     strcpy (buf, ourbuf);
  63.   }
  64.   return buf;
  65. }
  66.